<?php

1->pom
<dependency>
  <groupId>org.apache.logging.log4j</groupId>
  <artifactId>log4j-api</artifactId>
  <version>2.5</version>
</dependency>
<dependency>
  <groupId>org.apache.logging.log4j</groupId>
  <artifactId>log4j-core</artifactId>
  <version>2.5</version>
</dependency>
<dependency>
  <groupId>com.fasterxml.jackson.core</groupId>
  <artifactId>jackson-core</artifactId>
  <version>2.5.3</version>
</dependency>
<dependency>
  <groupId>net.logstash.log4j</groupId>
  <artifactId>jsonevent-layout</artifactId>
  <version>1.7</version>
</dependency>
<dependency>
  <groupId>com.fasterxml.jackson.core</groupId>
  <artifactId>jackson-databind</artifactId>
  <version>2.5.3</version>
</dependency>


2->配置文件 (log4j2.xml)

<Properties>
     <Property name="hostName2">$${ctx:hostName}</Property>
     <property name="application">应用名称</property>
 </Properties>
    <Appenders>
        <Console name="Console" target="SYSTEM_OUT">
         <JsonLayout eventEol="true"  complete="false"  properties="true" />
        </Console>
        <RollingFile name="RollingFileInfo" fileName="/var/log/app/application名字.log" filePattern="/var/log/app/application名字i.log">
       <JsonLayout eventEol="true" compact="true" complete="false"  properties="true" />
            <Policies>
                <SizeBasedTriggeringPolicy size="10MB" />
            </Policies>
            <DefaultRolloverStrategy max="9" />
        </RollingFile>
    </Appenders>
         <Loggers>
          <Root level="error">
           <property name="hostName">${hostName}</property>
           <property name="application">${application}</property>
         　<AppenderRef ref="RollingFileInfo"/>
          <AppenderRef ref="Console" />
          </Root>
     </Loggers>
</Configuration>
